<?php
namespace Apps\BoxEdu\Model;

use Think\Model;

class EduSubjectOrderModel extends \BaseModel
{

    public function load($id = "")
    {
        $data = BoxModel("system_order")->load($id);
        return $data;
    }

    /***********取消订单***/
    public function cancel($order_sn)
    {
        $data = $this->load($order_sn);
								//dump($data);exit();
								
        if ($data['status'] == 1) {
            $r = $this->where("order_sn='$order_sn'")->save(array('status' => 3));
            if ($num = $data['card_num']) {
                BoxModel("system_card")->where("num='$num'")->save(array('state' => 2));
            }
            /******取消返回课程学币***/
            $num = $data['yie'];
            $row = array(
                'user_id' => $data['user_id'],
                'num' => $num,
																'event'=>'00017',
                'order_sn' => $order_sn,
                'type' => "money",
                'subjectid' => $data['subjectid'],
            );
											//	dump($row);exit();
            if ($num > 0) {
                $r = Logic('BoxSns', 'Log')->add($row);
            }
        }

        return $r;
    }


    /***********订单的评论***/
    public function getComment($where, $limit = 10, $order = "id desc")
    {
        $topic = BoxModel("sns_topic");
        $comment = BoxModel("edu_order_topic");
        $data = $comment->get($where, $limit, $order);
        $re = array();
        foreach ($data['list'] as $one) {
            $row = $topic->load($one['topic_id']);
            $row = array_merge($row, $one);
            $row['subject'] = BoxModel("edu_subject")->where(array('subjectid' => $one['pid']))->find();
            $re[] = $row;

        }
        $data = array(
            'count' => $count,
            'list' => $re,
            'pager' => $page,
        );
        return $data;
    }


}
 